perm filename VARIAN.PAL[SYS,HE] blob sn#119352 filedate 1975-02-07 generic text, type C, neo UTF8
COMMENT āŠ—   VALID 00003 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	.SBTTL	variance operator
C00005 00003	
C00007 ENDMK
CāŠ—;
.SBTTL	variance operator

;assumes 4 bit samples packed two/byte
;OLD holds pointer to data block of form:

VSTR=0		; pointer to word in upper left corner of window
VBYT=2		; 0-3 to indicate starting sample of word
VWID=4		; window width in samples
VLEN=6		; window length in lines
VLCNT=10	; number of bytes per picture line (must be even)
VSIZ=12		; number of samples in window
VSCOR=14	; returns variance here as an integer*10

HYSTO:		; histogram table
	.BLKW 16.
VPTR:	0	; pointer to start of current line
LCNT:	0	; number of lines to go
SCNT:	0	; number of samples to go in line
BCNT:	0	; initial number of bytes to go in word
BSHFT:	0	; initial shift to align samples
AVE:	0	; average intensity*10

VARIAN:	MOV VSTR(OLD),VPTR
	MOV VLEN(OLD),LCNT
	MOV #HYSTO,C		; clear table
	MOV #16.,B
VLOPA:	CLR (C)+
	SOB B,VLOPA
	MOV VBYT(OLD),LENG	; initialize constants for first line start
	ASL LENG
	MOV DP1(LENG),BCNT
	MOV DP2(LENG),BSHFT
	CLR LENG		; LENG will hold sum of intensities
VLOPB:	MOV VPTR,NEW		; NEW points to current word
 	MOV VWID(OLD),SCNT	; set count for next line
	MOV (NEW)+,B		; align first sample of line
	ASH BSHFT,B
	MOV BCNT,C
	BR VLOPD

VLOPC:	MOV (NEW)+,B		; get next word
	MOV #4,C		; unpack samples
VLOPD:	ASHC #4,A
	BIC #177760,A		; clear high order bits
	ADD A,LENG		; update sum
	ASL A
	INC HYSTO(A)		; update histogram
	DEC SCNT
	BEQ VLOPF		; end of line
	SOB C,VLOPD
	BR VLOPC		; end of word

VLOPF:	ADD VLCNT(OLD),VPTR	; update for next line, if any
 	DEC LCNT
	BNE VLOPB
	CLR A			; histogram finished
	MOV LENG,B		; compute average*10
	MUL #10.,B
	DIV VSIZ(OLD),A
	MOV A,AVE
	CLR C			; generate variance
	MOV #HYSTO,NEW
	CLR B			; B is index*10 into histogram table
	MOV #16.,A
VLOPE:	MOV B,LENG
	SUB AVE,LENG
	BPL VLOP
	NEG LENG
VLOP:	MUL (NEW)+,LENG
	ADD LENG,C		; variance = (I*10-AVE*10)*HISTO[I]/SIZE
	ADD #10.,B
	SOB A,VLOPE
	CLR A
	MOV C,B
	DIV VSIZ(OLD),A
	MOV A,VSCOR(OLD)
	RTS PC

DP1:	
	.WORD	4,3,2,1		; initial sample count
DP2:
	.WORD	0,4,8.,12.	; initial shift